package incubator;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableColumnModel;




import quary.Quary;
import quary.QuaryBridge;
import quary.VinylData;
import quary.VinylDataVar;
import table.VinylTable;



public class TestMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(800,400);
	
		JScrollPane scrollPane = new JScrollPane();
		
		final QuaryBridge quaryBridge = new QuaryBridge();
		final VinylTable vinylTable = new VinylTable(scrollPane, quaryBridge);
		
		
		JPanel panel = new JPanel();
		panel.setLayout(new BorderLayout());
		
		panel.add(scrollPane, BorderLayout.PAGE_START);
		
		JButton delete = new JButton("Delete Selected");
		panel.add(delete, BorderLayout.SOUTH);
		delete.addActionListener(new ActionListener() {
//			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				ArrayList<Object> keys = new ArrayList<Object>();
				
				for (int i = 0; i < vinylTable.getRowCount(); i++) {
					
					
					if (vinylTable.isRowChecked(i)) {
						keys.add(vinylTable.getValueAt(i, 1));
					}
				}
				if (keys.size() != 0) {
					quaryBridge.deleteFromDatabase(VinylData.VINYL, VinylData.VINYL_ID, keys.toArray());
				}
			}
		});
		
		
		frame.add(panel);
		
		frame.setVisible(true);
		
		vinylTable.activate();

	}

}
